import 'package:flutter/material.dart';

class ticaiitem extends StatelessWidget {
  final String stockName;
  final String stockRate;
  final bool isDarkMode;

  ticaiitem({
    required this.stockName,
    required this.stockRate,
    required this.isDarkMode,
  });

  @override
  Widget build(BuildContext context) {
    double screenWidth = MediaQuery.of(context).size.width;
    double responsiveFontSize = screenWidth * 0.035;
    double responsiveContainerPadding = screenWidth * 0.015;

    // 判断 stockRate 的第一个字符是否为 "-"
    Color rateColor = stockRate.startsWith('-') ? Color(0xFF1CAA3C) : Color(0xFFF2233B);

    return Expanded(
      child: Container(
        decoration: BoxDecoration(
          color: isDarkMode ? Color(0xFF252525) : Color(0xFFF5F5F5),
          borderRadius: BorderRadius.circular(4),
        ),
        padding: EdgeInsets.symmetric(
          vertical: responsiveContainerPadding,
          horizontal: responsiveContainerPadding * 1.5,
        ),
        child: Flex(
          direction: Axis.horizontal, // 水平方向布局
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            // 使用 Expanded 替代 Flexible，使得股票名称部分占据剩余空间
            Expanded(
              child: Text(
                stockName,
                style: TextStyle(
                  color: isDarkMode ? Colors.white : Colors.black,
                  fontSize: responsiveFontSize,
                  fontWeight: FontWeight.w400,
                ),
                overflow: TextOverflow.ellipsis,
              ),
            ),
            // 股票涨跌幅部分
            Text(
              stockRate,
              style: TextStyle(
                color: rateColor,
                fontSize: responsiveFontSize,
              ),
            ),
          ],
        ),
      ),
    );
  }

}
